﻿namespace DimensionsHelper.Client.ViewModels;

public class StringPairViewModel : ObservableCollection<StringKeyValuePairViewModel>
{
    public void ToDictionary(Dictionary<string, string> targetDictionary, bool ignoreEmptyKey = true)
    {
        foreach (StringKeyValuePairViewModel item in this)
        {
            if (ignoreEmptyKey && string.IsNullOrEmpty(item.Key))
            {
                continue;
            }

            if (!targetDictionary.TryAdd(item.Key, item.Value))
            {
                targetDictionary[item.Key] = item.Value;
            }
        }
    }


    public void FromDictionary(IDictionary<string, string> dict)
    {
        foreach (KeyValuePair<string, string> item in dict)
        {
            Add(new StringKeyValuePairViewModel { Key = item.Key, Value = item.Value });
        }
    }
}